# 导包
import app


# 定义接口类
class LoginAPI:

    # 初始化
    def __init__(self):
        self.get_img_code_url = app.BASE_URL + '/common/public/verifycode1/{}'
        self.get_phone_code_url = app.BASE_URL + '/member/public/sendSms'
        self.register_url = app.BASE_URL + '/member/public/reg'
        self.login_url = app.BASE_URL + '/member/public/login'

    # 获取图片验证码
    def get_img_code(self, session, r):
        return session.get(url=self.get_img_code_url.format(r))

    # 获取短信验证码
    def get_phone_code(self, session, phone, phone_code):
        phone_data = {"phone": phone, "imgVerifyCode": phone_code, "type": "reg"}
        return session.post(url=self.get_phone_code_url, data=phone_data)

    # 注册
    def register(self, session, phone, pwd='test123', verifycode='8888', phone_code='666666', dy_server='on', invite_phone=''):
        register_data = {"phone": phone, "password": pwd, "verifycode": verifycode, "phone_code": phone_code, "dy_server": dy_server, "invite_phone": invite_phone}
        return session.post(url=self.register_url, data=register_data)

    # 定义登录接口方法
    def login(self, session, phone, pwd='test123'):
        login_data = {"keywords": phone, "password": pwd}
        return session.post(self.login_url, data=login_data)









































